package com.atguigu.day31.session04;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/sessionB")
public class SessionServletB extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("SessionServletB 请求到达了");

        HttpSession session = req.getSession();
        System.out.println(" SessionServletB session.isNew() = " + session.isNew());
        System.out.println(" SessionServletB session.getId() = " + session.getId());

        Object userNameValue = session.getAttribute("userName");

        System.out.println("userNameValue = " + userNameValue);

        System.out.println("SessionServletB Success");
        resp.getWriter().println("SessionServletB Success");

    }
}
